var dataList;
var imgs = [];
var imgtext = [];
document.addEventListener('plusready',function(){
	showWating();
	//轮播图
	$.ajax({ 
		type:"get",  
		url: apiRoot+'?m=Home&c=article&a=scroll',
		data : {
			taid : 2
		},
		dataType :'json',
		success : function(data){  
			plus.nativeUI.closeWaiting();
			var data = data.home;
			if(data.length > 0){
				$.each(data, function(index , value){ 
					imgtext.push(value.name);
					imgs.push({"i":index,'img':value.adfile.replace('/uploads', webRoot+'/uploads')});
				}); 
				slider.init(); 
//				var zhuye = '';
//				zhuye = '<div class="mui-slider-item mui-slider-item-duplicate"><a href="#"><img style="height:180px;" src="'+ webRoot + data[(data).length-1].adfile +'"/><p class="mui-slider-title">'+ data[(data).length-1].name +'</p></a></div>';
//				$.each(data, function(index , value){ 
//					zhuye +='<div class="mui-slider-item"><a href="#"><img style="height:180px;" src="'+ webRoot + value.adfile +'" /><p class="mui-slider-title">'+ value.name +'</p></a></div>'; 
//				});     
//				zhuye += '<div class="mui-slider-item mui-slider-item-duplicate"><a href="#"><img style="height:180px;" src="'+ webRoot + data[0].adfile +'"/><p class="mui-slider-title">'+ data[0].name +'</p></a></div>'; 
//				$('.banner2').html(zhuye);
			}
		},
		error : function(e){
			console.log(JSON.stringify(e));
		}
	})
	//资讯
	$.ajax({
		type : "get",
		url : apiRoot+"?m=home&c=article&a=allNews",
		dataType :'json',
		success : function(data){
			if(data.length > 0){
				dataList = data;
				newList(dataList);
			}
		},
		error : function(e){
			console.log(JSON.stringify(e));
			errortoast();
		}
	});
	//搜索
	$('.search').on('input paste', function() {
		if(dataList.length > 0){
			var search = $('.search').val();
			if(!search.trim()){
				newList(dataList);
				return;
			}
			$('.newsList .home-list').each(function(k, v) {
				var _this = $(this);
				var name = _this.find('.font-17').text();
				if(name.indexOf(search) >= 0){
					_this.show();
				}else{
					_this.hide();
				}
			})
		}
	})
})
function newList(arr){
	var list = '';
	$.each(arr, function(k,v) {
		list += '<div class="mui-table-view background table-view-cell home-list" data-id="'+v.id+'">'+
					'<div>'+
						'<img src="'+webRoot+v.litpic+'" alt="" />'+
					'</div>'+
					'<div class="">'+
						'<li class="font-17">'+v.title+'</li>'+
						'<li class="mui-ellipsis-2 font-12">'+v.description+'</li>'+
					'</div>'+
					'<div class="clear-both new-time">'+
					'<span>'+v.issuedname+'</span>&emsp;<span>'+v.addtime+'</span>'+
					'</div>'+
				'</div>';
	}); 
	$('.newsList').html(list);
	$('.home-list').unbind('click');
	$('.home-list').on('click',function(){
		var id = $(this).attr('data-id');
		goNewPage('jk-new.html',{aid:id});
	})
}
